// game/food.go

package game

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	"image/color"
	"math/rand"
)

type Food struct {
	x, y int
}

func NewFood() *Food {
	food := &Food{}
	food.RandomizePosition()
	return food
}
func (f *Food) RandomizePosition() {
	maxX := ScreenWidth/gridSize - 2 // -2是为了避免在边界生成
	maxY := ScreenHeight/gridSize - 2
	f.x = rand.Intn(maxX) + 1
	f.y = rand.Intn(maxY) + 1
}
func (f *Food) Draw(screen *ebiten.Image) {
	green := color.RGBA{0, 255, 0, 255}

	x, y := f.x*gridSize, f.y*gridSize
	ebitenutil.DrawRect(screen, float64(x), float64(y), gridSize, gridSize, green)

}
